package com.ymtms.statisticalform.controller;

import com.ymtms.statisticalform.pojo.CollectingMoneyBalance;
import com.ymtms.statisticalform.service.CollectingMoneyBalanceService;
import com.ymtms.statisticalform.util.TimeRangeUtil;
import com.ymtms.statisticalform.util.ValidateUtil;
import com.ymtms.statisticalform.vo.GridRequest;
import com.ymtms.statisticalform.vo.GridResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CollectingMoneyBalanceController {
    @Autowired
    CollectingMoneyBalanceService collectingMoneyBalanceService;

    @RequestMapping("/cmblist")
    @ResponseBody
//  @RequestParam Map<String, String> params
//  可以使用实体类来实现接收其他参数
    public GridResult<CollectingMoneyBalance> cmblist(GridRequest gridRequest, /* 封装页面中laiyu表格所传过来的基本信息*/
            CollectingMoneyBalance collectingMoneyBalance, /*实体类接收非范围参数*/
            @RequestParam(value = "balanceDate", required = false) String balanceDate){
        String beginTime = "";
        String endTime = "";
        if (ValidateUtil.isNotEmpty(balanceDate)) {
            String[] split = balanceDate.split(" - ");
            beginTime = split[0];
            endTime = split[1];
        }
        System.out.println("gridRequest:"+gridRequest);
        System.out.println("collectingMoneyBalance:"+collectingMoneyBalance);
        System.out.println("balanceDate:"+balanceDate);
        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(
                gridRequest, collectingMoneyBalance, new TimeRangeUtil(beginTime, endTime));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(Integer.parseInt(params.get("page")), Integer.parseInt(params.get("limit")));
//        GridResult<CollectingMoneyBalance> result = collectingMoneyBalanceService.queryByPage(1,10);
        result.setCode(0);
        result.setMsg("");
        System.out.println(result);
        return result;
    }
}
